from PyQt5 import QtWidgets
from PyQt5 import *

def __init__(self, parent=None):        
    super(Form, self).__init__(parent)        
    self.browser = QTextBrowser()        
    self.lineedit = QLineEdit("Type an expression and press Enter") 
    self.lineedit.selectAll()        
    layout = QVBoxLayout()        
    layout.addWidget(self.browser)        
    layout.addWidget(self.lineedit)        
    self.setLayout(layout)        
    self.lineedit.setFocus()        
    self.connect(self.lineedit, SIGNAL("returnPressed()"), self.updateUi)        
    self.setWindowTitle("Calculate coding by Kaysin")

def updateUi(self):        
    try:            
        text = unicode(self.lineedit.text())            
        self.browser.append("%s = <b>%s</b>" % (text, eval(text))) 
        except:            
            self.browser.append( "<font color=red>%s is invalid!</font>" % text)

app = QApplication(sys.argv)
form = Form()
form.show()
app.exec_()

